package com.atguigu.rabitmq.consumer.listener04;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class ConsumerListenerDirect {

    // 为测试消息可靠型消费暂时频闭，因为多个方法监听一个队列时，需要进行竞争或者测试的方法不一定能第一个抢到队列进行消费
    // @RabbitListener(queues = "direct_queue_01")
    // public void consumer01(Message message) {
    //     byte[] body = message.getBody();
    //     String msg = new String(body);
    //     System.out.println("consumer01 ...msg ----> " + msg);
    // }

    @RabbitListener(queues = "direct_queue_02")
    public void consumer02(Message message, Channel channel) throws IOException {
        byte[] body = message.getBody();
        String msg = new String(body);
        System.err.println("consumer02....msg ----> " + msg);

        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        channel.basicAck(deliveryTag, true);
    }
}